SELECT
    i_tm.itemid          item_id,
    i_tm.itemstring      item_name,
    i_tm.itemtype        item_type,
    i_un.id              result_unit,
    GROUP_CONCAT(i_u2.id          ORDER BY i_u2.id) units_id,
    GROUP_CONCAT(i_u2.itemunit    ORDER BY i_u2.id) units_name,
    GROUP_CONCAT(i_u2.quantity    ORDER BY i_u2.id) units_quan,
    GROUP_CONCAT(i_u2.Barcode     ORDER BY i_u2.id) units_barcode,
    GROUP_CONCAT(i_pr.sellprice   ORDER BY i_u2.id) units_sell,
    GROUP_CONCAT(i_pr.buyprice    ORDER BY i_u2.id) units_buy
FROM   itemunitequivalent i_un
JOIN   items              i_tm ON i_tm.itemid     = i_un.theitemid
JOIN   itemsprices        i_pr ON i_pr.itemid     = i_tm.itemid
JOIN   itemstypes         i_ty ON i_ty.itemtypeid = i_tm.itemtype
JOIN   itemunitequivalent i_u2 ON i_u2.theitemid  = i_tm.itemid
WHERE  i_u2.itemunit = i_pr.itemunit
  AND  (i_un.Barcode LIKE @kw OR i_tm.itemstring LIKE @kw)
  AND  i_pr.pricelistid = @pl
GROUP  BY i_tm.itemid
LIMIT  @max